package com.Impl;

import com.dao.BaseDao;
import com.dao.productDao;
import com.entity.product;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class productDaoImpl extends BaseDao implements productDao {
  //构造方法
  public productDaoImpl(Connection con){
    super(con);
  }
  @Override
  public List<product> findAll() {
    List<product> list = new ArrayList<>();
    String sql = "select * from product";
    ResultSet rs = this.executeQuery(sql,null);
    try {
      while(rs.next()){
        product product = new product();
        product.setPid(rs.getInt("pid"));
        product.setSpid(rs.getInt("spid"));
        product.setPname(rs.getString("pname"));
        product.setPbrief(rs.getString("pbrief"));
        product.setPrice(rs.getDouble("price"));
        product.setPathPic(rs.getString("pathPic"));
        list.add(product);
      }
    } catch (SQLException throwables) {
      throwables.printStackTrace();
    }
    return list;
  }

  @Override
  public boolean addProduct(product product) {
    return false;
  }
}
